#include "stdafx.h"
#include "Chypering.h"


AC::BlockData<BLOCK_LEN> EncodeCBC(
	const AC::AES::Key<KEY_LEN> key, 
	const AC::AES::IV iv, 
	const AC::BlockData<BLOCK_LEN> input)
{
	AC::AES::Encryptor<KEY_LEN, BLOCK_LEN> enc;
	AC::ChypertextStealing<KEY_LEN, BLOCK_LEN>::Encryption cts;
	typedef AC::CBC<KEY_LEN, BLOCK_LEN, AC::AES::Encryptor<KEY_LEN, BLOCK_LEN>, AC::ChypertextStealing<KEY_LEN, BLOCK_LEN>::Encryption> cbce;

	AC::BlockData<BLOCK_LEN> output;
	cbce::Encryption cbcEnc;

	enc.SetKey(key);
	cbcEnc.Process(enc, cts, iv, input, output);

	return output;
};

AC::BlockData<BLOCK_LEN> DecodeCBC(
	const AC::AES::Key<KEY_LEN> key, 
	const AC::AES::IV iv, 
	const AC::BlockData<BLOCK_LEN> input)
{
	AC::AES::Decryptor<KEY_LEN, BLOCK_LEN> dec;
	AC::ChypertextStealing<KEY_LEN, BLOCK_LEN>::Decryption cts;
	typedef AC::CBC<KEY_LEN, BLOCK_LEN, AC::AES::Decryptor<KEY_LEN, BLOCK_LEN>, AC::ChypertextStealing<KEY_LEN, BLOCK_LEN>::Decryption> cbcd;

	AC::BlockData<BLOCK_LEN> output;
	cbcd::Decryption cbcDec;

	dec.SetKey(key);
	cbcDec.Process(dec, cts, iv, input, output);

	return output;
};

AC::BlockData<BLOCK_LEN> EncodeOFB(
	const AC::AES::Key<KEY_LEN> key, 
	const AC::AES::IV iv, 
	const AC::BlockData<BLOCK_LEN> input)
{
	AC::AES::Encryptor<KEY_LEN, BLOCK_LEN> enc;
	AC::TruncatePadding<KEY_LEN, BLOCK_LEN>::Encryption trunc;
	//typedef AC::OFB<KEY_LEN, BLOCK_LEN, AC::AES::Encryptor<KEY_LEN, BLOCK_LEN>, AC::TruncatePadding<KEY_LEN, BLOCK_LEN>::Encryption> ofbe;
	typedef AC::OFB<KEY_LEN, BLOCK_LEN, AC::AES::Encryptor<KEY_LEN, BLOCK_LEN>> ofbe;

	AC::BlockData<BLOCK_LEN> output;
	ofbe::Encryption ofbEnc;

	enc.SetKey(key);
	ofbEnc.Process(enc, trunc, iv, input, output);

	return output;
};

AC::BlockData<BLOCK_LEN> DecodeOFB(
	const AC::AES::Key<KEY_LEN> key, 
	const AC::AES::IV iv, 
	const AC::BlockData<BLOCK_LEN> input)
{
	AC::AES::Encryptor<KEY_LEN, BLOCK_LEN> enc;
	AC::TruncatePadding<KEY_LEN, BLOCK_LEN>::Encryption trunc;
	typedef AC::OFB<KEY_LEN, BLOCK_LEN, AC::AES::Encryptor<KEY_LEN, BLOCK_LEN>> ofbd;

	AC::BlockData<BLOCK_LEN> output;
	ofbd::Decryption ofbDec;

	enc.SetKey(key);
	ofbDec.Process(enc, trunc, iv, input, output);

	return output;
};
